package com.beerandjesus.sportofkings.handicapper.app.spring;

import org.springframework.context.ApplicationListener;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.apache.log4j.Logger;
import com.beerandjesus.sportofkings.handicapper.dao.Database;

/**
 * Date: Sep 10, 2012
 * Time: 9:38:01 PM
 */
public class HandicapperApplicationListener implements ApplicationListener {
    private Database database;
    private static final Logger LOG = Logger.getLogger(HandicapperApplicationListener.class);

    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        if (ContextRefreshedEvent.class.isAssignableFrom(applicationEvent.getClass())) {
            System.out.println("INFO: HandicapperApplicationListener - intializing Database");
            getDatabase().init();
        }
    }

    public Database getDatabase() {
        return database;
    }

    public void setDatabase(Database database) {
        this.database = database;
    }
}
